﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AdministratorHelper
{
    public partial class SelectForm : Form
    {
        public SelectForm()
        {
            InitializeComponent();
        }

        AppDb db = new AppDb();
        private void SelectForm_Load(object sender, EventArgs e)
        {
            var list = db.GetAll();

            for (int i = 0; i < list.Count(); i++)
            {
                Button btn = new Button();
                btn.Text = list[i].AppName;
                btn.Tag = list[i].AppPath;
                btn.Click += OnClick;
                flowLayoutPanel1.Controls.Add(btn);
            }
        }

        private void OnClick(object sender, EventArgs e)
        {
            var btn = (Button)sender;
            AdminProcHelper.RunElevated(btn.Tag.ToString());
            this.Hide();
        }


        private void SelectForm_Deactivate(object sender, EventArgs e)
        {
            this.Close();

        }

        private void SelectForm_Shown(object sender, EventArgs e)
        {
            this.Activate();
        }
    }
}
